package app.fugema.shop.main.goods.adapter;

import com.base.common.utils.DensityUtil;
import com.base.common.view.adapter.ada.BaseRVAdapter;
import com.base.common.view.adapter.connector.BaseItemMultiType;
import com.base.common.view.adapter.connector.BaseItemTypeInterface;
import com.base.common.view.adapter.connector.BaseViewHolder;

import android.graphics.Paint;
import android.view.View;
import android.view.ViewGroup;

import app.fugema.shop.R;
import app.fugema.shop.databinding.ItemCateGoodsListViewBinding;
import app.fugema.shop.main.goods.model.CateGoodsPageBean;
import app.fugema.shop.main.goods.view.GoodsDetailActivity;
import app.fugema.shop.main.goods.view.SimilarGoodsActivity;


public class LinerGoodsItemBaseItemMultiType extends BaseItemMultiType<CateGoodsPageBean.ProductBean, ItemCateGoodsListViewBinding>
{

    @Override
    public int getItemViewType()
    {
        return BaseItemTypeInterface.TYPE_CHILD_TWO;
    }

    @Override
    public boolean isFullSpanType()
    {
        return true;
    }

    @Override
    public int getLayoutId()
    {
        return R.layout.item_cate_goods_list_view;
    }


    @Override
    public void onBindViewHolder(ItemCateGoodsListViewBinding binding, int position, CateGoodsPageBean.ProductBean bean)
    {
        super.onBindViewHolder(binding, position, bean);
    }

    @Override
    public void onBindViewHolder(ItemCateGoodsListViewBinding binding, int position, BaseViewHolder viewHolder, CateGoodsPageBean.ProductBean bean)
    {
        super.onBindViewHolder(binding, position, viewHolder, bean);
        if (viewHolder.getAdapter() != null) {

            binding.tvDeletePrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);

            int pos = getFirstPosition(viewHolder.getAdapter());
            if (pos != -1) {

                if (binding.rclItemView.getLayoutParams() instanceof ViewGroup.MarginLayoutParams)
                {
                    ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) binding.rclItemView.getLayoutParams();
                    /*
                    int spc = position - pos;
                    if (spc % 2 == 0) {
                        marginLayoutParams.leftMargin = DensityUtil.getDimens(R.dimen.dp_15);
                    } else {
                        marginLayoutParams.leftMargin = DensityUtil.getDimens(R.dimen.dp_5);
                    }
                    */
                    binding.rclItemView.setLayoutParams(marginLayoutParams);
                }
            }
        }
    }

    @Override
    public void onItemClick(View view, BaseRVAdapter adapter, int onclickType, int position, CateGoodsPageBean.ProductBean bean)
    {
        super.onItemClick(view, adapter, onclickType, position, bean);
        switch (view.getId())
        {
            case R.id.clItemView:
                GoodsDetailActivity.start(view.getContext(), bean.getProductId());
                break;
            case R.id.btn_similar:
                SimilarGoodsActivity.start(view.getContext(), bean.getProductId());
                break;
            default:
                GoodsDetailActivity.start(view.getContext(), bean.getProductId());
                break;
        }
    }

    private int getFirstPosition(BaseRVAdapter adapter)
    {
        return adapter.getFirstPosition(getItemViewType(), 0);
    }

}
